﻿using MediatR;
using SheepCultivation.Common.Domain.main;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;

namespace SheepCultivation.API.AddliCation.Tip_newspaper
{
    public class TransplantingBackSeachHandler : IRequestHandler<TransplantingBackSeachCommon, Result>
    {
        public readonly IBaseRepository<Descendent> DescendentRepository;
        public TransplantingBackSeachHandler(IBaseRepository<Descendent> descendentRepository)
        {
            DescendentRepository = descendentRepository;
        }
        public async Task<Result> Handle(TransplantingBackSeachCommon request, CancellationToken cancellationToken)
        {
            var res = new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                res.Code = (int)CommonEnumCode.success;
                var list = DescendentRepository.GetAll().FirstOrDefault(x => x.breedingSheepArchiveId == request.BreedingSheepArchiveId);
                res.Code = (int)CommonEnumCode.success;
                res.Data = list;
                res.Msg = "后裔转种反填";
            }
            catch (Exception)
            {

                throw;
            }
            return res;
        }
    }
}
